{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Copyright 2021-2023 @ Shenzhen Bay Laboratory & Peking University & Huawei Technologies Co., Ltd\n",
    "\n",
    "This code is a part of MindSPONGE:\n",
    "MindSpore Simulation Package tOwards Next Generation molecular modelling.\n",
    "\n",
    "MindSPONGE is open-source software based on the AI-framework:\n",
    "MindSpore (https://www.mindspore.cn/)\n",
    "\n",
    "Licensed under the Apache License, Version 2.0 (the \"License\");\n",
    "you may not use this file except in compliance with the License.\n",
    "\n",
    "You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n",
    "\n",
    "Unless required by applicable law or agreed to in writing, software\n",
    "distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "\n",
    "See the License for the specific language governing permissions and\n",
    "limitations under the License.\n",
    "\n",
    "MindSPONGE advanced tutorial 01: Collective variables (CVs), metrics and analyse."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mindspore import context\n",
    "from mindsponge import Sponge\n",
    "from mindsponge import ForceField\n",
    "from mindsponge import set_global_units\n",
    "from mindsponge import Protein\n",
    "from mindsponge import UpdaterMD\n",
    "from mindsponge.optimizer import SteepestDescent\n",
    "from mindsponge.control import VelocityVerlet\n",
    "from mindsponge.callback import WriteH5MD, RunInfo\n",
    "from mindsponge.control import Langevin\n",
    "from mindsponge.function import VelocityGenerator\n",
    "from mindsponge.colvar import Torsion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "context.set_context(mode=context.PYNATIVE_MODE, device_target=\"GPU\")\n",
    "set_global_units('nm', 'kj/mol')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "system = Protein(pdb='alad.pdb')\n",
    "potential = ForceField(system, 'AMBER.FF14SB')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "phi = Torsion([4, 6, 8, 14])\n",
    "psi = Torsion([6, 8, 14, 16])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Using fully connected neighbour list (not updated).\n"
     ]
    }
   ],
   "source": [
    "min_opt = SteepestDescent(system.trainable_params(), 1e-7)\n",
    "mini = Sponge(system, potential, min_opt, metrics={'phi': phi, 'psi': psi})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "phi [[3.1415927]]\n",
      "psi [[3.1415927]]\n"
     ]
    }
   ],
   "source": [
    "cv = mini.analyse()\n",
    "for k, v in cv.items():\n",
    "    print(k, v)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Started simulation at 2023-05-18 15:37:05\n",
      "[MindSPONGE] Step: 0, E_pot: -55.75643, phi: -3.140886, psi: -3.1410766\n",
      "[MindSPONGE] Step: 10, E_pot: -58.40555, phi: -3.1340268, psi: -3.1368413\n",
      "[MindSPONGE] Step: 20, E_pot: -60.168476, phi: -3.1277595, psi: -3.1337605\n",
      "[MindSPONGE] Step: 30, E_pot: -61.549706, phi: -3.1221528, psi: -3.131402\n",
      "[MindSPONGE] Step: 40, E_pot: -62.696198, phi: -3.1171532, psi: -3.1295478\n",
      "[MindSPONGE] Step: 50, E_pot: -63.674084, phi: -3.112676, psi: -3.1280725\n",
      "[MindSPONGE] Step: 60, E_pot: -64.52254, phi: -3.1086385, psi: -3.1268952\n",
      "[MindSPONGE] Step: 70, E_pot: -65.268196, phi: -3.1049676, psi: -3.1259575\n",
      "[MindSPONGE] Step: 80, E_pot: -65.93031, phi: -3.1016028, psi: -3.1252148\n",
      "[MindSPONGE] Step: 90, E_pot: -66.52346, phi: -3.0984938, psi: -3.1246324\n",
      "[MindSPONGE] Finished simulation at 2023-05-18 15:37:08\n",
      "[MindSPONGE] Simulation time: 3.51 seconds.\n",
      "--------------------------------------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<mindsponge.core.sponge.Sponge at 0x7fc615870880>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "run_info = RunInfo(10)\n",
    "mini.run(100, callbacks=[run_info])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "phi [[-3.0958812]]\n",
      "psi [[-3.1242208]]\n"
     ]
    }
   ],
   "source": [
    "cv = mini.analyse()\n",
    "for k, v in cv.items():\n",
    "    print(k, v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "vgen = VelocityGenerator(300)\n",
    "velocity = vgen(system.shape, system.atom_mass)\n",
    "opt = UpdaterMD(\n",
    "    system,\n",
    "    integrator=VelocityVerlet(system),\n",
    "    thermostat=Langevin(system, 300),\n",
    "    time_step=1e-3,\n",
    "    velocity=velocity\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Using fully connected neighbour list (not updated).\n"
     ]
    }
   ],
   "source": [
    "md = Sponge(system, potential, opt, metrics={'phi': phi, 'psi': psi})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Started simulation at 2023-05-18 15:37:13\n",
      "[MindSPONGE] Step: 0, E_pot: -67.05887, E_kin: 83.896034, E_tot: 16.837166, Temperature: 320.3293, phi: -3.0950527, psi: -3.1256313\n",
      "[MindSPONGE] Step: 10, E_pot: -21.73536, E_kin: 43.650623, E_tot: 21.915264, Temperature: 166.66551, phi: -3.0601666, psi: 3.1363442\n",
      "[MindSPONGE] Step: 20, E_pot: -20.185848, E_kin: 64.18463, E_tot: 43.998783, Temperature: 245.06786, phi: -2.9961138, psi: 3.0761726\n",
      "[MindSPONGE] Step: 30, E_pot: -30.493969, E_kin: 79.76107, E_tot: 49.2671, Temperature: 304.54135, phi: -2.9470093, psi: 2.9815526\n",
      "[MindSPONGE] Step: 40, E_pot: -30.656712, E_kin: 66.40468, E_tot: 35.747967, Temperature: 253.54434, phi: -2.857146, psi: 2.9238849\n",
      "[MindSPONGE] Step: 50, E_pot: -49.14535, E_kin: 92.3302, E_tot: 43.18485, Temperature: 352.5324, phi: -2.7445993, psi: 2.9843612\n",
      "[MindSPONGE] Step: 60, E_pot: -28.700012, E_kin: 68.57472, E_tot: 39.87471, Temperature: 261.82996, phi: -2.7263236, psi: 3.0381215\n",
      "[MindSPONGE] Step: 70, E_pot: -28.18718, E_kin: 71.60406, E_tot: 43.416878, Temperature: 273.39648, phi: -2.7240217, psi: 2.9241073\n",
      "[MindSPONGE] Step: 80, E_pot: -40.055573, E_kin: 87.310074, E_tot: 47.2545, Temperature: 333.36472, phi: -2.563725, psi: 2.822133\n",
      "[MindSPONGE] Step: 90, E_pot: -10.430702, E_kin: 64.56222, E_tot: 54.131516, Temperature: 246.50952, phi: -2.41647, psi: 2.8361874\n",
      "[MindSPONGE] Step: 100, E_pot: -34.878155, E_kin: 91.017624, E_tot: 56.13947, Temperature: 347.52078, phi: -2.4351444, psi: 2.882155\n",
      "[MindSPONGE] Step: 110, E_pot: -23.416069, E_kin: 82.17691, E_tot: 58.76084, Temperature: 313.76544, phi: -2.4825945, psi: 2.8110974\n",
      "[MindSPONGE] Step: 120, E_pot: -15.82399, E_kin: 77.98988, E_tot: 62.165894, Temperature: 297.77866, phi: -2.400364, psi: 2.806629\n",
      "[MindSPONGE] Step: 130, E_pot: -8.005829, E_kin: 80.10366, E_tot: 72.09783, Temperature: 305.8494, phi: -2.2619827, psi: 2.8167112\n",
      "[MindSPONGE] Step: 140, E_pot: -0.39691162, E_kin: 72.874016, E_tot: 72.477104, Temperature: 278.2454, phi: -2.2335732, psi: 2.8771937\n",
      "[MindSPONGE] Step: 150, E_pot: 9.129372, E_kin: 79.46943, E_tot: 88.5988, Temperature: 303.4278, phi: -2.223051, psi: 2.8902898\n",
      "[MindSPONGE] Step: 160, E_pot: 13.543922, E_kin: 90.12035, E_tot: 103.664276, Temperature: 344.09485, phi: -2.262131, psi: 2.8147516\n",
      "[MindSPONGE] Step: 170, E_pot: -3.5193863, E_kin: 101.44969, E_tot: 97.930305, Temperature: 387.35217, phi: -2.2151532, psi: 2.6893466\n",
      "[MindSPONGE] Step: 180, E_pot: 11.173584, E_kin: 84.070404, E_tot: 95.24399, Temperature: 320.9951, phi: -2.2155135, psi: 2.6126595\n",
      "[MindSPONGE] Step: 190, E_pot: -5.6957855, E_kin: 102.55263, E_tot: 96.85684, Temperature: 391.5634, phi: -2.1990921, psi: 2.5234652\n",
      "[MindSPONGE] Step: 200, E_pot: -12.432259, E_kin: 110.77266, E_tot: 98.3404, Temperature: 422.94885, phi: -2.237728, psi: 2.4950294\n",
      "[MindSPONGE] Step: 210, E_pot: -9.26442, E_kin: 91.457016, E_tot: 82.1926, Temperature: 349.19846, phi: -2.2006621, psi: 2.453453\n",
      "[MindSPONGE] Step: 220, E_pot: -12.228241, E_kin: 88.03186, E_tot: 75.80362, Temperature: 336.1206, phi: -2.0813346, psi: 2.3828669\n",
      "[MindSPONGE] Step: 230, E_pot: -17.176193, E_kin: 71.58862, E_tot: 54.41243, Temperature: 273.33755, phi: -2.0096166, psi: 2.375056\n",
      "[MindSPONGE] Step: 240, E_pot: -18.042755, E_kin: 62.017426, E_tot: 43.97467, Temperature: 236.79308, phi: -2.1095777, psi: 2.344643\n",
      "[MindSPONGE] Step: 250, E_pot: -19.74022, E_kin: 76.52597, E_tot: 56.78575, Temperature: 292.18918, phi: -2.1403766, psi: 2.29841\n",
      "[MindSPONGE] Step: 260, E_pot: -12.8767395, E_kin: 66.818146, E_tot: 53.941406, Temperature: 255.12306, phi: -2.0494125, psi: 2.2692175\n",
      "[MindSPONGE] Step: 270, E_pot: -4.680588, E_kin: 48.60645, E_tot: 43.92586, Temperature: 185.58769, phi: -1.9237183, psi: 2.2534425\n",
      "[MindSPONGE] Step: 280, E_pot: -19.413078, E_kin: 65.73761, E_tot: 46.32453, Temperature: 250.99739, phi: -2.012186, psi: 2.341371\n",
      "[MindSPONGE] Step: 290, E_pot: -22.600052, E_kin: 56.048656, E_tot: 33.448605, Temperature: 214.0033, phi: -2.1365347, psi: 2.3615758\n",
      "[MindSPONGE] Step: 300, E_pot: -22.42144, E_kin: 69.91058, E_tot: 47.489143, Temperature: 266.9305, phi: -2.1801493, psi: 2.3225493\n",
      "[MindSPONGE] Step: 310, E_pot: -17.1232, E_kin: 67.00798, E_tot: 49.88478, Temperature: 255.84789, phi: -2.255961, psi: 2.3349946\n",
      "[MindSPONGE] Step: 320, E_pot: -34.317123, E_kin: 69.34975, E_tot: 35.032623, Temperature: 264.78912, phi: -2.252814, psi: 2.361073\n",
      "[MindSPONGE] Step: 330, E_pot: -22.163322, E_kin: 58.2256, E_tot: 36.06228, Temperature: 222.31526, phi: -2.125493, psi: 2.403667\n",
      "[MindSPONGE] Step: 340, E_pot: -21.767143, E_kin: 62.32753, E_tot: 40.560387, Temperature: 237.97711, phi: -2.0616274, psi: 2.4776835\n",
      "[MindSPONGE] Step: 350, E_pot: -35.749737, E_kin: 79.66699, E_tot: 43.917255, Temperature: 304.18213, phi: -2.0705147, psi: 2.4279227\n",
      "[MindSPONGE] Step: 360, E_pot: -33.222843, E_kin: 71.97257, E_tot: 38.74973, Temperature: 274.80353, phi: -2.2036698, psi: 2.3790383\n",
      "[MindSPONGE] Step: 370, E_pot: -25.774063, E_kin: 67.91768, E_tot: 42.143616, Temperature: 259.32126, phi: -2.2327914, psi: 2.3877785\n",
      "[MindSPONGE] Step: 380, E_pot: -32.073044, E_kin: 61.64126, E_tot: 29.568214, Temperature: 235.35681, phi: -2.181873, psi: 2.4422038\n",
      "[MindSPONGE] Step: 390, E_pot: -15.201302, E_kin: 55.536587, E_tot: 40.335285, Temperature: 212.04814, phi: -2.1395428, psi: 2.4774354\n",
      "[MindSPONGE] Step: 400, E_pot: -15.466606, E_kin: 74.62956, E_tot: 59.162956, Temperature: 284.94836, phi: -2.1649828, psi: 2.6148078\n",
      "[MindSPONGE] Step: 410, E_pot: -30.761047, E_kin: 79.93906, E_tot: 49.17801, Temperature: 305.22092, phi: -2.1723406, psi: 2.6478932\n",
      "[MindSPONGE] Step: 420, E_pot: -24.648926, E_kin: 65.80694, E_tot: 41.158012, Temperature: 251.26208, phi: -2.26315, psi: 2.7288728\n",
      "[MindSPONGE] Step: 430, E_pot: -26.136494, E_kin: 60.761005, E_tot: 34.62451, Temperature: 231.99586, phi: -2.3095746, psi: 2.6922143\n",
      "[MindSPONGE] Step: 440, E_pot: -30.001648, E_kin: 78.97016, E_tot: 48.968513, Temperature: 301.5215, phi: -2.3162441, psi: 2.6418333\n",
      "[MindSPONGE] Step: 450, E_pot: -25.37735, E_kin: 67.614716, E_tot: 42.237366, Temperature: 258.1645, phi: -2.3241477, psi: 2.6046035\n",
      "[MindSPONGE] Step: 460, E_pot: -21.777306, E_kin: 61.497505, E_tot: 39.7202, Temperature: 234.80794, phi: -2.4050562, psi: 2.6284156\n",
      "[MindSPONGE] Step: 470, E_pot: -22.895535, E_kin: 76.06698, E_tot: 53.171444, Temperature: 290.43668, phi: -2.5339015, psi: 2.5937963\n",
      "[MindSPONGE] Step: 480, E_pot: -18.28846, E_kin: 69.690605, E_tot: 51.402145, Temperature: 266.09058, phi: -2.6417682, psi: 2.5981183\n",
      "[MindSPONGE] Step: 490, E_pot: -24.835175, E_kin: 77.02933, E_tot: 52.194153, Temperature: 294.11108, phi: -2.5831726, psi: 2.6980221\n",
      "[MindSPONGE] Step: 500, E_pot: -28.515152, E_kin: 77.354744, E_tot: 48.839592, Temperature: 295.35358, phi: -2.541808, psi: 2.729101\n",
      "[MindSPONGE] Step: 510, E_pot: -21.19944, E_kin: 62.694466, E_tot: 41.495026, Temperature: 239.37814, phi: -2.6062732, psi: 2.710171\n",
      "[MindSPONGE] Step: 520, E_pot: -31.826134, E_kin: 68.28456, E_tot: 36.458427, Temperature: 260.72208, phi: -2.6915584, psi: 2.6960995\n",
      "[MindSPONGE] Step: 530, E_pot: -20.69426, E_kin: 62.630024, E_tot: 41.935764, Temperature: 239.1321, phi: -2.799937, psi: 2.7068095\n",
      "[MindSPONGE] Step: 540, E_pot: -10.841263, E_kin: 59.660004, E_tot: 48.81874, Temperature: 227.79204, phi: -2.8131576, psi: 2.7523334\n",
      "[MindSPONGE] Step: 550, E_pot: -32.794506, E_kin: 84.189575, E_tot: 51.39507, Temperature: 321.4501, phi: -2.7669752, psi: 2.776445\n",
      "[MindSPONGE] Step: 560, E_pot: -8.571808, E_kin: 70.18524, E_tot: 61.613434, Temperature: 267.9792, phi: -2.677073, psi: 2.7614431\n",
      "[MindSPONGE] Step: 570, E_pot: -27.994865, E_kin: 90.44815, E_tot: 62.453285, Temperature: 345.34644, phi: -2.6991262, psi: 2.8027482\n",
      "[MindSPONGE] Step: 580, E_pot: -12.275223, E_kin: 65.79996, E_tot: 53.524734, Temperature: 251.23543, phi: -2.7507126, psi: 2.8035123\n",
      "[MindSPONGE] Step: 590, E_pot: -11.237289, E_kin: 74.501175, E_tot: 63.263885, Temperature: 284.45816, phi: -2.7083762, psi: 2.702255\n",
      "[MindSPONGE] Step: 600, E_pot: 4.6767426, E_kin: 62.240284, E_tot: 66.91702, Temperature: 237.644, phi: -2.6151674, psi: 2.66897\n",
      "[MindSPONGE] Step: 610, E_pot: -10.366287, E_kin: 85.63321, E_tot: 75.26692, Temperature: 326.96216, phi: -2.6122909, psi: 2.7346473\n",
      "[MindSPONGE] Step: 620, E_pot: -8.802948, E_kin: 95.67758, E_tot: 86.87463, Temperature: 365.3133, phi: -2.5990696, psi: 2.8198714\n",
      "[MindSPONGE] Step: 630, E_pot: -13.703537, E_kin: 104.741196, E_tot: 91.03766, Temperature: 399.9197, phi: -2.6494265, psi: 2.8652425\n",
      "[MindSPONGE] Step: 640, E_pot: -11.1992035, E_kin: 85.62924, E_tot: 74.43004, Temperature: 326.947, phi: -2.7611322, psi: 2.8762145\n",
      "[MindSPONGE] Step: 650, E_pot: -3.3482208, E_kin: 85.809685, E_tot: 82.461464, Temperature: 327.636, phi: -2.736221, psi: 2.8911796\n",
      "[MindSPONGE] Step: 660, E_pot: 15.427963, E_kin: 68.09383, E_tot: 83.52179, Temperature: 259.9938, phi: -2.6702325, psi: 2.9391603\n",
      "[MindSPONGE] Step: 670, E_pot: -4.9867783, E_kin: 93.92718, E_tot: 88.9404, Temperature: 358.62994, phi: -2.7756886, psi: 2.9432707\n",
      "[MindSPONGE] Step: 680, E_pot: -23.294258, E_kin: 87.03119, E_tot: 63.73693, Temperature: 332.2999, phi: -2.9030902, psi: 2.8973002\n",
      "[MindSPONGE] Step: 690, E_pot: -11.880524, E_kin: 73.24308, E_tot: 61.362556, Temperature: 279.65454, phi: -2.9675734, psi: 2.8221416\n",
      "[MindSPONGE] Step: 700, E_pot: -22.469177, E_kin: 77.97899, E_tot: 55.50981, Temperature: 297.73706, phi: -2.96601, psi: 2.7580025\n",
      "[MindSPONGE] Step: 710, E_pot: -28.12732, E_kin: 80.70001, E_tot: 52.572693, Temperature: 308.12637, phi: -2.8562627, psi: 2.7981064\n",
      "[MindSPONGE] Step: 720, E_pot: -23.613434, E_kin: 72.41307, E_tot: 48.799637, Temperature: 276.4854, phi: -2.8300376, psi: 2.8575428\n",
      "[MindSPONGE] Step: 730, E_pot: -32.822807, E_kin: 79.33808, E_tot: 46.515274, Temperature: 302.9263, phi: -2.8481596, psi: 2.8572698\n",
      "[MindSPONGE] Step: 740, E_pot: -22.53724, E_kin: 71.92845, E_tot: 49.391212, Temperature: 274.63507, phi: -2.757651, psi: 2.8907642\n",
      "[MindSPONGE] Step: 750, E_pot: -16.540497, E_kin: 76.22704, E_tot: 59.686546, Temperature: 291.04782, phi: -2.6042848, psi: 2.978945\n",
      "[MindSPONGE] Step: 760, E_pot: -20.598434, E_kin: 91.46129, E_tot: 70.862854, Temperature: 349.21475, phi: -2.583915, psi: 2.986955\n",
      "[MindSPONGE] Step: 770, E_pot: 2.510315, E_kin: 91.99223, E_tot: 94.50255, Temperature: 351.242, phi: -2.534995, psi: 2.9403563\n",
      "[MindSPONGE] Step: 780, E_pot: -9.169357, E_kin: 99.40616, E_tot: 90.2368, Temperature: 379.54962, phi: -2.4490888, psi: 2.9830205\n",
      "[MindSPONGE] Step: 790, E_pot: -6.1693573, E_kin: 91.724045, E_tot: 85.55469, Temperature: 350.21802, phi: -2.4094617, psi: 2.9986298\n",
      "[MindSPONGE] Step: 800, E_pot: 1.2831573, E_kin: 78.99019, E_tot: 80.273346, Temperature: 301.598, phi: -2.4639063, psi: 2.9781325\n",
      "[MindSPONGE] Step: 810, E_pot: -0.6298218, E_kin: 71.90012, E_tot: 71.2703, Temperature: 274.52692, phi: -2.4338107, psi: 2.9536874\n",
      "[MindSPONGE] Step: 820, E_pot: -1.7520294, E_kin: 61.285446, E_tot: 59.533417, Temperature: 233.99826, phi: -2.4489598, psi: 3.0368128\n",
      "[MindSPONGE] Step: 830, E_pot: -9.738907, E_kin: 72.12752, E_tot: 62.38861, Temperature: 275.39514, phi: -2.5132136, psi: 3.115756\n",
      "[MindSPONGE] Step: 840, E_pot: -20.174988, E_kin: 64.82796, E_tot: 44.65297, Temperature: 247.52417, phi: -2.5427089, psi: 3.1013453\n",
      "[MindSPONGE] Step: 850, E_pot: -17.566006, E_kin: 74.99826, E_tot: 57.432255, Temperature: 286.3561, phi: -2.576366, psi: 2.984186\n",
      "[MindSPONGE] Step: 860, E_pot: -23.827858, E_kin: 90.31014, E_tot: 66.482285, Temperature: 344.8195, phi: -2.5740705, psi: 2.9204907\n",
      "[MindSPONGE] Step: 870, E_pot: 0.3965683, E_kin: 60.971016, E_tot: 61.367584, Temperature: 232.7977, phi: -2.5931077, psi: 2.9071238\n",
      "[MindSPONGE] Step: 880, E_pot: -23.137878, E_kin: 72.422935, E_tot: 49.285057, Temperature: 276.52307, phi: -2.637222, psi: 2.9306347\n",
      "[MindSPONGE] Step: 890, E_pot: -15.609283, E_kin: 66.514366, E_tot: 50.905083, Temperature: 253.96318, phi: -2.654437, psi: 2.9682283\n",
      "[MindSPONGE] Step: 900, E_pot: -24.923065, E_kin: 65.11456, E_tot: 40.191498, Temperature: 248.61847, phi: -2.6860507, psi: 2.956407\n",
      "[MindSPONGE] Step: 910, E_pot: -12.39082, E_kin: 55.791912, E_tot: 43.401093, Temperature: 213.02301, phi: -2.6865296, psi: 2.8831801\n",
      "[MindSPONGE] Step: 920, E_pot: -13.951942, E_kin: 61.862732, E_tot: 47.91079, Temperature: 236.20244, phi: -2.622672, psi: 2.9061637\n",
      "[MindSPONGE] Step: 930, E_pot: -32.57421, E_kin: 90.95768, E_tot: 58.38347, Temperature: 347.2919, phi: -2.5895512, psi: 2.876444\n",
      "[MindSPONGE] Step: 940, E_pot: -24.98082, E_kin: 80.94801, E_tot: 55.967194, Temperature: 309.07327, phi: -2.5980477, psi: 2.8270378\n",
      "[MindSPONGE] Step: 950, E_pot: -25.341682, E_kin: 85.059326, E_tot: 59.717644, Temperature: 324.771, phi: -2.621634, psi: 2.7963104\n",
      "[MindSPONGE] Step: 960, E_pot: 0.67004395, E_kin: 68.62326, E_tot: 69.293304, Temperature: 262.0153, phi: -2.5377023, psi: 2.790343\n",
      "[MindSPONGE] Step: 970, E_pot: 0.45584106, E_kin: 74.74987, E_tot: 75.20571, Temperature: 285.4077, phi: -2.465715, psi: 2.8584082\n",
      "[MindSPONGE] Step: 980, E_pot: -9.720184, E_kin: 81.14985, E_tot: 71.429665, Temperature: 309.84393, phi: -2.493514, psi: 2.8428292\n",
      "[MindSPONGE] Step: 990, E_pot: -10.13092, E_kin: 96.572815, E_tot: 86.441895, Temperature: 368.73145, phi: -2.5108411, psi: 2.730323\n",
      "[MindSPONGE] Finished simulation at 2023-05-18 15:37:27\n",
      "[MindSPONGE] Simulation time: 13.91 seconds.\n",
      "--------------------------------------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<mindsponge.core.sponge.Sponge at 0x7fc60d0a3e80>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cb_h5md = WriteH5MD(system, 'tutorial_a01.h5md', save_freq=10)\n",
    "md.run(1000, callbacks=[run_info, cb_h5md])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "phi [[-2.4289787]]\n",
      "psi [[2.7230694]]\n"
     ]
    }
   ],
   "source": [
    "cv = md.analyse()\n",
    "for k, v in cv.items():\n",
    "    print(k, v)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mindspore-1.10",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
